package day4;

import java.util.concurrent.locks.ReentrantLock;

//b.写两个线程，一个线程打印 1-52，
//另一个线程打印A-Z，保证打印顺序是12A34B…5152Z；
//实现方式: 公平锁
public class Work1 {
    ReentrantLock lock=new ReentrantLock(true);
    int num=1;
    int ch=65;
    public void print(){
        String name=Thread.currentThread().getName();
        lock.lock();
        if("0".equals(name)){//打印数字
            System.out.print(num+""+(num+1));
            num+=2;
        }else{//打印字母
            System.out.print((char)ch);
            ch++;
        }
        lock.unlock();
    }
    public static void main(String[] args) {
        Work1 w=new Work1();
        for(int i=0;i<2;i++){
            new Thread(()->{
                for(int j=0;j<26;j++){
                    w.print();
                }
            },i+"").start();
        }
    }
}
